package com.hongyuan.sellcoach.ui.home.view_mode;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.mvvmhabitx.bus.event.SingleLiveEvent;
import com.hongyuan.mvvmhabitx.utils.ToastUtils;
import com.hongyuan.sellcoach.base.CustomViewModel;
import com.hongyuan.sellcoach.data.Constants;
import com.hongyuan.sellcoach.data.MyRepository;
import com.hongyuan.sellcoach.ui.home.beans.HomeContentBean;

public class CancelAppointmentViewMode extends CustomViewModel<MyRepository> {

    //选中项
    public ObservableField<HomeContentBean.ListBean> entity = new ObservableField<>();

    public CancelAppointmentViewMode(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        //弹框输入驳回理由
        public SingleLiveEvent<Void> showEdit = new SingleLiveEvent<>();
    }

    //拨打电话
    public BindingCommand callTel = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            getUC().getCallTel().setValue(entity.get().getM_mobile());
        }
    });

    //驳回处理
    public BindingCommand disallowance = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            uc.showEdit.call();
        }
    });

    //申请通过
    public BindingCommand submit = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            setParams("cpa_id",String.valueOf(entity.get().getCpa_id()))
                    .requestData(Constants.JL_AGREE_CANCEL);
        }
    });


    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);

        if(code == Constants.JL_UN_AGREE_CANCEL){
            ToastUtils.showShort("已驳回");
            finish();
        }

        if(code == Constants.JL_AGREE_CANCEL){
            ToastUtils.showShort("已取消该课程");
            finish();
        }
    }
}
